{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Landsat8 product\n", "\n", "Landsat8 product stage-in example." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import the Python packages" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "%matplotlib inline\n", "\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")\n", "import os\n", "import sys\n", "import glob\n", "os.environ['_CIOP_APPLICATION_PATH']=''\n", "sys.path.append('/opt/anaconda/bin/')\n", "import cioppy\n", "ciop = cioppy.Cioppy()\n", "\n", "import numpy as np\n", "import matplotlib\n", "import matplotlib.pyplot as plt\n", "import matplotlib.colors as colors\n", "\n", "from snappy import jpy\n", "from snappy import ProductIO\n", "from snappy import GPF\n", "from snappy import HashMap\n", "\n", "import gc\n", "\n", "from shapely.wkt import loads " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Search parameters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set the catalogue endpoint to Sentinel-1:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "series = 'https://catalog.terradue.com/landsat8/search'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the time of interest:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "start_date = '2017-09-01T00:00:00'\n", "stop_date = '2017-12-10T23:59:59'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the area of interest:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "geom = 'MULTIPOLYGON (((6.4788 14.5973, 7.5577 14.5973, 7.5577 13.6328, 6.4788 13.6328, 6.4788 14.5973)), ((67.7116 37.9032, 68.791 37.9032, 68.791 36.9211, 67.7116 36.9211, 67.7116 37.9032)), ((-10.3668 15.3471, -9.351800000000001 15.3471, -9.351800000000001 14.3406, -10.3668 14.3406, -10.3668 15.3471)), ((67.62430000000001 36.7228, 68.116 36.7228, 68.116 35.6923, 67.62430000000001 35.6923, 67.62430000000001 36.7228)))'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check the WKT validity:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "loads(geom)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Build and submit the catalog search\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "search_params = dict([('geom', geom),\n", " ('start', start_date),\n", " ('do', 'terradue'),\n", " ('stop', stop_date)])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [], "source": [ "search = ciop.search(end_point = series,\n", " params = search_params,\n", " output_fields='self,enclosure,identifier', \n", " model='GeoTime')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(0, 'LC08_L1TP_154035_20171210_20180525_01_T1')\n", "(1, 'LC08_L1TP_154034_20171210_20180525_01_T1')\n", "(2, 'LC08_L1TP_154033_20171210_20180525_01_T1')\n", "(3, 'LC08_L1TP_190051_20171206_20171223_01_T1')\n", "(4, 'LC08_L1TP_190050_20171206_20171223_01_T1')\n", "(5, 'LC08_L1TP_201050_20171203_20171207_01_T1')\n", "(6, 'LC08_L1TP_201049_20171203_20171207_01_T1')\n", "(7, 'LC08_L1GT_153035_20171203_20171207_01_T2')\n", "(8, 'LC08_L1GT_153034_20171203_20171207_01_T2')\n", "(9, 'LC08_L1TP_155034_20171201_20171207_01_T1')\n", "(10, 'LC08_L1TP_155033_20171201_20171207_01_T1')\n", "(11, 'LC08_L1TP_189051_20171129_20171207_01_T1')\n", "(12, 'LC08_L1TP_189050_20171129_20171207_01_T1')\n", "(13, 'LC08_L1TP_200050_20171126_20171206_01_T1')\n", "(14, 'LC08_L1TP_200049_20171126_20171206_01_T1')\n", "(15, 'LC08_L1GT_154035_20171124_20171206_01_T2')\n", "(16, 'LC08_L1TP_154034_20171124_20171206_01_T1')\n", "(17, 'LC08_L1TP_154033_20171124_20171206_01_T1')\n", "(18, 'LC08_L1TP_190051_20171120_20171206_01_T1')\n", "(19, 'LC08_L1TP_190050_20171120_20171206_01_T1')\n" ] } ], "source": [ "for index, elem in enumerate(search):\n", " print(index, elem['identifier'])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "ls8_index = 2" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ls8_identifier = search[ls8_index]['identifier']\n", "ls8_reference = search[ls8_index]['self']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Prepare the variables assignment for the Jupyter Notebook streaming executable" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "input_identifier = 'LC08_L1TP_154033_20171210_20180525_01_T1'\n" ] } ], "source": [ "print 'input_identifier = \\'%s\\'' % ls8_identifier" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "input_reference = 'https://catalog.terradue.com/landsat8/search?format=atom&uid=LC08_L1TP_154033_20171210_20180525_01_T1'\n" ] } ], "source": [ "print 'input_reference = \\'%s\\'' % ls8_reference" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Stage-in the data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the local folder where to stage-in the data to:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "data_path = os.path.join(os.sep,'workspace','tmp','data')" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "source": [ "if not os.path.isdir(data_path):\n", " os.makedirs(data_path)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [], "source": [ "try:\n", " retrieved = ciop.copy(search[ls8_index]['enclosure'], data_path)\n", "except:\n", " retrieved = os.path.join(data_path, search[ls8_index]['identifier'])" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "product_path = os.path.join(data_path, ls8_identifier)\n", "\n", "if not os.path.isdir(product_path):\n", " os.makedirs(product_path)\n", "\n", "os.chdir(product_path)\n", "\n", "import tarfile\n", "tar = tarfile.open(retrieved)\n", "tar.extractall()\n", "tar.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### List Archive content\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "['LC08_L1TP_154033_20171210_20180525_01_T1_ANG.txt',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B1.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B10.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B11.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B2.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B3.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B4.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B5.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B6.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B7.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B8.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_B9.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_BQA.TIF',\n", " 'LC08_L1TP_154033_20171210_20180525_01_T1_MTL.txt']" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "products = [ name for name in os.listdir('.') ]\n", "\n", "products" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 2 }